import 'package:flutter/material.dart';
import 'package:navigate_demo/main_single_file.dart';
import 'package:navigate_demo/screens/detail_screen.dart';
import 'package:navigate_demo/screens/basic_screen.dart';
import 'package:navigate_demo/screens/home_screen.dart';
import 'package:navigate_demo/screens/payment_screen.dart';
import 'package:navigate_demo/screens/settings_screen.dart';
import 'package:navigate_demo/screens/args/detail_args.dart';

import 'router_names.dart';

class AppRouter {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RouterNames.home:
        return MaterialPageRoute(builder: (_) => const HomeScreen());
      case RouterNames.basic:
        return MaterialPageRoute(builder: (_)=>const BasicScreen());
      case RouterNames.detail:
        final args = settings.arguments as DetailArgs?;
        return MaterialPageRoute(
            builder: (_)=>DetailScreen(
              productId:args?.productId??0,
              productName:args?.productName ?? '未知商品',
            ),);
      case RouterNames.payment:
        return MaterialPageRoute(builder: (_)=>const PaymentScreen());
      case RouterNames.settings:
        return MaterialPageRoute(builder: (_)=>const SettingsScreen());
      default:
        return MaterialPageRoute(builder: (_)=>Scaffold(
          body: Center(
            child: Text('找不到路由：${settings.name}'),
          ),
        ));
    }
  }
}
